package day1;

import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class SetTest {
    public static void main(String[] args) {
        //无序，不可重复
        Set<String> set=new HashSet<>();
        set.add("dog");
        set.add("cat");
        set.add("snake");
        set.add("dog");
        System.out.println(set.size());
        System.out.println(set);
        System.out.println("1遍历");
        for(String s:set)
            System.out.println(s);
        System.out.println("遍历方法2：");
//        for (int i = 0; i <set.size() ; i++) {
//
//        }
        String[] objects =  set.toArray(new String[0]);
        System.out.println(objects.length);
        System.out.println(Arrays.toString(objects));
        System.out.println("----第三种遍历。。。");
        Iterator<String> ir = set.iterator();
        while (ir.hasNext()){//还有没有下一个
            String next = ir.next();
            System.out.println(next);
        }
    }
}
